package com.mvc.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.mvc.domain.User;
import com.mvc.domain.UserList;

public class UserServiceImp implements UserService {

	@Override
	public User findbyUsername(String username) {
		Map<String, User> usermap = UserList.getUsermap();
		User user = usermap.get(username);
		return user;
	}

	@Override
	public int addUser(User user) {
		Map<String, User> usermap = UserList.getUsermap();
		usermap.put(user.getUsername(), user);
		UserList.setUsermap(usermap);
		return 0;
	}

	@Override
	public List<User> listUser() {
		Map<String, User> usermap = UserList.getUsermap();
		List<User> userlist = new ArrayList<User>();
		Set<String> usernames = usermap.keySet();
		for (String username : usernames) {
			userlist.add(usermap.get(username));
		}
		return userlist;
	}

}
